<template>
  <a-card :bordered="false">
    <h2>迁移策略设置</h2>
    <a-form
      :form="form"
      :label-col="{ span: 2 }"
      :wrapper-col="{ span: 12 }"
      @submit="handleSubmit"
    >
      <a-form-item label="迁移策略">
        <a-radio-group
          v-decorator="[
            'config',
            {
              rules: [{ required: true, message: '迁移策略不能为空' }],
            },
          ]"
        >
          <a-radio v-for="d in list" :key="d.value" :value="d.value">
            {{ d.name }}
          </a-radio>
        </a-radio-group>
      </a-form-item>
      <a-form-item :wrapper-col="{ span: 12, offset: 2 }">
        <a-button type="primary" html-type="submit"> 提交 </a-button>
      </a-form-item>
    </a-form>
  </a-card>
</template>

<script>
import { getAction, gPostAction } from "@/api/manage";

export default {
  name: "F020301",
  data() {
    return {
      formLayout: "horizontal",
      form: this.$form.createForm(this, { name: "coordinated" }),
      list: [],
    };
  },
  mounted() {
    this.loadData();
  },
  methods: {
    loadData() {
      getAction("/scheduler/scheduler_strategy_config_list", {}).then((res) => {
        this.list = res.data;
        this.list.forEach((item) => {
          if (item.isCheck) {
            this.form.setFieldsValue({
              config: item.value,
            });
          }
        });
      });
    },
    handleSubmit(e) {
      e.preventDefault();
      this.form.validateFields((err, values) => {
        if (!err) {
          gPostAction("/scheduler/update_scheduler_strategy_config", {
            config: values.config,
          }).then((res) => {
            if (res.success) {
              this.$message.success("操作成功");
            }
          });
        }
      });
    },
    handleSelectChange(value) {
      // console.log(value)
      this.form.setFieldsValue({
        note: `Hi, ${value === "male" ? "man" : "lady"}!`,
      });
    },
  },
  watch: {},
};
</script>